<template>
  <div class="date">
    <span>日期</span>
    <el-date-picker
      @change="dateChange"
      v-model="date"
      type="daterange"
      value-format="yyyy-MM-dd"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      :picker-options="pickerOptions">
    </el-date-picker>
  </div>
</template>
<script>
import { formatDate } from '@/utils/utils'
export default {
  data () {
    return {
      date: '',
      pickerOptions: {
          disabledDate (time) {
              return time.getTime() > Date.now()
          }
      }
    }
  },
  created () {
    this.setDate()
  },
  methods: {
    setDate () {
      let start = formatDate(new Date().getTime() - 3600 * 1000 * 24 * 14, 'YYYY-MM-DD')
      let end = formatDate(new Date(), 'YYYY-MM-DD')
      this.date = [start, end]
    },
    dateChange (date) {
      this.$emit('getDate', date)
    }
  }
}
</script>
<style lang="scss" scoped>
  .date{
    span{
      margin-right: 10px;
      font-size: 14px;
    }
  }
</style>
